package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.BoatLocationInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IBoatLocationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 船舶位置信息Controller
 *
 * @author zjw
 * @date 2024-01-24
 */
@RestController
@RequestMapping("/system/boatLocationInfo")
public class BoatLocationInfoController extends BaseController {
    @Autowired
    private IBoatLocationInfoService boatLocationInfoService;

    /**
     * 查询船舶位置信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(BoatLocationInfo boatLocationInfo) {
        startPage();
        List<BoatLocationInfo> list = boatLocationInfoService.selectBoatLocationInfoList(boatLocationInfo);
        return getDataTable(list);
    }

    /**
     * 导出船舶位置信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "船舶位置信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BoatLocationInfo boatLocationInfo) {
        List<BoatLocationInfo> list = boatLocationInfoService.selectBoatLocationInfoList(boatLocationInfo);
        ExcelUtil<BoatLocationInfo> util = new ExcelUtil<BoatLocationInfo>(BoatLocationInfo.class);
        util.exportExcel(response, list, "船舶位置信息数据");
    }

    /**
     * 获取船舶位置信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(boatLocationInfoService.selectBoatLocationInfoById(id));
    }

    /**
     * 新增船舶位置信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "船舶位置信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BoatLocationInfo boatLocationInfo) {
        return toAjax(boatLocationInfoService.insertBoatLocationInfo(boatLocationInfo));
    }

    /**
     * 修改船舶位置信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "船舶位置信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BoatLocationInfo boatLocationInfo) {
        return toAjax(boatLocationInfoService.updateBoatLocationInfo(boatLocationInfo));
    }

    /**
     * 删除船舶位置信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "船舶位置信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(boatLocationInfoService.deleteBoatLocationInfoByIds(ids));
    }
}
